package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/shop/type")
public class TypeController {

    @Autowired
    TbTypeService tbTypeService;

    /**
     * @return com.bwie.utils.Result
     * @description 添加产品分页
     * @params [tbType]
     * @author 杰
     * @date 2025/5/24 10:13
     */
    @PostMapping
    public Result addType(@RequestBody TbType tbType) {

        return tbTypeService.addType(tbType);

    }


    /**
     * @return com.bwie.utils.Result
     * @description 删除
     * @params []
     * @author 杰
     * @date 2025/5/24 10:19
     */
    @DeleteMapping("/deleteType/{typeId}")
    public Result deleteType(@PathVariable(name = "typeId") Integer typeId) {

        return tbTypeService.deleteType(typeId);
    }


    /**
     * @description 类型分页列表
     * @params []
     * @return com.bwie.utils.Result
     * @author 杰
     * @date 2025/5/26 17:43
     */
    @GetMapping
    public Result getTypeList() {
        return tbTypeService.getTypeList();
    }

    @PostMapping("/getTypeListSelect")
    public Result getTypeListSelect() {
        return tbTypeService.getTypeList();
    }



    /**
     * @description 改变类型列表的状态
     * @params [typeId, status]
     * @return com.bwie.utils.Result
     * @author 杰
     * @date 2025/5/26 18:30
     */
    @PostMapping("/changeTypeStatus/{typeId}/{status}")
    public Result changeTypeStatus(@PathVariable(name = "typeId") Integer typeId,@PathVariable(name = "status") Integer status){

        return tbTypeService.changeTypeStatus(typeId,status);

    }


    /**
     * @description 根据id删除该类型
     * @params [typeId]
     * @return com.bwie.utils.Result
     * @author 杰
     * @date 2025/5/26 18:35
     */
    @PostMapping("/deleteTypeById/{typeId}")
    public Result deleteTypeById(@PathVariable(name = "typeId") Integer typeId){

        return tbTypeService.deleteTypeById(typeId);
    }


    @PostMapping("/uploadeImage")
    public Result uploadeImage(@RequestPart("file")MultipartFile file){

        return tbTypeService.uploadeImage(file);
    }

    /**
     * @description 修改类型
     * @params [tbType]
     * @return com.bwie.utils.Result
     * @author 杰
     * @date 2025/5/26 20:58
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType){
        return tbTypeService.updateType(tbType);
    }
}
